Skip to content

fix: always take a fresh backup before uploading to S3 - #28

Closed
iamimmanuelraj wants to merge 3 commits into
frappe:developfrom
iamimmanuelraj:fix/reuse-path-missing-site-config
Closed

fix: always take a fresh backup before uploading to S3#28
iamimmanuelraj wants to merge 3 commits into
frappe:developfrom
iamimmanuelraj:fix/reuse-path-missing-site-config

Conversation

@iamimmanuelraj

@iamimmanuelraj iamimmanuelraj commented Jul 31, 2026

Copy link
Copy Markdown

When the database dump exceeds 1GB, validate_file_size() sets frappe.flags.create_new_backup = False, so backup_to_s3() skips new_backup() and reuses whatever backup files are already on disk.

That reuse path is broken:

  • get_recent_backup() picks the newest file of each type independently, so the db and files can come from different backup runs.
  • It returns None for the site config whenever no *-site_config_backup.json is present on disk. On Frappe Cloud the local config gets removed by the offsite agent after upload (frappe/agent Site.upload_offsite_backup), so this happens routinely.

The next line then crashes:

File ".../s3_backup_settings.py", line 183, in backup_to_s3
    upload_file_to_s3(site_config, folder, conn, bucket)
File ".../s3_backup_settings.py", line 194, in upload_file_to_s3
    destpath = os.path.join(folder, os.path.basename(filename))
TypeError: expected str, bytes or os.PathLike object, not NoneType

Result: only the database file lands in S3, then the job dies and the user gets a "Backup Upload Failed" email even though a backup exists.

Fix

Always call new_backup(force=True) in backup_to_s3(). The db, site config, and (optionally) files then always come from one consistent run and the config is guaranteed to exist. This removes the validate_file_size size check and the entire reuse path; ignore_files mirrors the existing "Backup Files" setting.

Note

This dumps the full database on every scheduled run (which is the intended behaviour for an offsite backup). The previous size-based reuse was what produced inconsistent, partial uploads.

backup_to_s3() reuses on-disk backups when create_new_backup is False
(large DBs). get_recent_backup() returns None for the site config when no
site_config_backup file exists on disk, so upload_file_to_s3(site_config)
crashes with 'expected str, bytes or os.PathLike object, not NoneType' and
only the database file gets uploaded.

Regenerate the site config via BackupGenerator.copy_site_config() when it is
missing, so the config is always uploaded alongside the database.
backup_to_s3() reused existing on-disk backups when the db dump exceeded 1GB
(via validate_file_size / create_new_backup). That reuse path selected the
newest file of each type independently, so it could stitch a db and files from
different runs, and get_recent_backup() returned None for the site config when
no site_config_backup file was present on disk, crashing the upload:

    upload_file_to_s3(site_config, ...)   # os.path.basename(None) -> TypeError

leaving only the database uploaded and emailing 'Backup Upload Failed'.

Always call new_backup(force=True) so db, site config and (optionally) files
come from one consistent run. Removes the size check and reuse path;
ignore_files mirrors the 'Backup Files' setting.

Note: dumps the full database on every run.
@iamimmanuelraj iamimmanuelraj changed the title fix: regenerate site config when reusing existing backup (NoneType crash) fix: always take a fresh backup before uploading to S3 Jul 31, 2026
After a successful offsite upload, call delete_temp_backups() so the fresh full
backups produced each run don't accumulate on disk. Deletes local backup files
older than keep_backups_for_hours; does not affect what was just uploaded.
@iamimmanuelraj iamimmanuelraj closed this by deleting the head repository Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant